package com.xinggq.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 网关路由配置
 * 
 * @author xinggq
 * @since 1.0.0
 */
@Configuration
public class GatewayRouteConfig {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                // 认证中心服务路由 - 不使用stripPrefix，保持完整路径
                .route("auth-center-service", r -> r
                        .path("/auth-center-service/**")
                        .filters(f -> f
                                .addRequestHeader("X-Target-Service", "auth-center-service"))
                        .uri("lb://auth-center-service"))
                // 用户中心服务路由 - 不使用stripPrefix，保持完整路径
                .route("user-center-service", r -> r
                        .path("/user-center-service/**")
                        .filters(f -> f
                                .addRequestHeader("X-Target-Service", "user-center-service"))
                        .uri("lb://user-center-service"))
                .build();
    }
}